package conversion;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class ConversionStringToDouble {

	public Double convertStringToDouble(String value){
		Locale locale = new Locale("pl", "PL");
		Locale.setDefault(locale);
		NumberFormat numberFormat = NumberFormat.getInstance();
		Double resultNumber = 11.5;
		try {
			if(Class.forName("java.lang.Long").isInstance(numberFormat.parse(value))){
				resultNumber = Double.parseDouble(String.valueOf(numberFormat.parse(value)));
			}
			else {
				resultNumber = (Double) numberFormat.parse(new String(value));
			}
		}
		catch (ClassNotFoundException el) {
			el.printStackTrace();
		}
		catch (ParseException el){
			el.printStackTrace();
		}
		return resultNumber;
	}
	
}
